﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BinarySearchTree
{
    class TreeNode<T>
    {
        private T value = default(T);
        private TreeNode<T> left = null;
        private TreeNode<T> right = null;
        private TreeNode<T> parent = null;

        public T Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        public TreeNode<T> Left
        {
            get { return this.left; }
            set { this.left = value; }
        }

        public TreeNode<T> Right
        {
            get { return this.right; }
            set { this.right = value; }
        }

        public TreeNode<T> Parent
        {
            get { return this.parent; }
            set { this.parent = value; }
        }

        public bool IsLeft
        {
            get { return (this.parent != null && this.parent.Left == this); }
        }

        public bool IsRight
        {
            get { return (this.parent != null && this.parent.Right == this); }
        }

        public TreeNode(T value, TreeNode<T> parent, TreeNode<T> left, TreeNode<T> right)
        {
            this.value = value;
            this.parent = parent;
            this.left = left;
            this.right = right;
        }

        public TreeNode(T value, TreeNode<T> parent) : this(value, parent, null, null) { }

        public TreeNode(T value) : this(value, null, null, null) { }
    }
}
